/**
 *  @(#)  IFAAAuthenticator  module    1.0  2017/03/24
 *
 *  Copyright  (c)  2017,  IFAA  and/or  its  affiliates.  All  rights  reserved.
 *
 *  Redistribution  and  use  in  source  and  binary  forms,  with  or  without
 *  modification,  are  permitted  provided  that  the  following  conditions  are  met:
 *
 *  -Redistribution  of  source  code  must  retain  the  above  copyright  notice,  this
 *    list  of  conditions  and  the  following  disclaimer.
 *
 *  -Redistribution  in  binary  form  must  reproduce  the  above  copyright  notice,
 *    this  list  of  conditions  and  the  following  disclaimer  in  the  documentation
 *    and/or  other  materials  provided  with  the  distribution.
 *
 *  Neither  the  name  of  IFAA  or  the  names  of  contributors  may
 *  be  used  to  endorse  or  promote  products  derived  from  this  software  without
 *  specific  prior  written  permission.
 *
 *  This  software  is  provided  "AS  IS,"  without  a  warranty  of  any  kind.  ALL
 *  EXPRESS  OR  IMPLIED  CONDITIONS,  REPRESENTATIONS  AND  WARRANTIES,  INCLUDING
 *  ANY  IMPLIED  WARRANTY  OF  MERCHANTABILITY,  FITNESS  FOR  A  PARTICULAR  PURPOSE
 *  OR  NON-INFRINGEMENT,  ARE  HEREBY  EXCLUDED.  IFAA,  ORG.
 *  AND  ITS  LICENSORS  SHALL  NOT  BE  LIABLE  FOR  ANY  DAMAGES  SUFFERED  BY  LICENSEE
 *  AS  A  RESULT  OF  USING,  MODIFYING  OR  DISTRIBUTING  THIS  SOFTWARE  OR  ITS
 *  DERIVATIVES.  IN  NO  EVENT  WILL  IFAA  OR  ITS  LICENSORS  BE  LIABLE  FOR  ANY  LOST
 *  REVENUE,  PROFIT  OR  DATA,  OR  FOR  DIRECT,  INDIRECT,  SPECIAL,  CONSEQUENTIAL,
 *  INCIDENTAL  OR  PUNITIVE  DAMAGES,  HOWEVER  CAUSED  AND  REGARDLESS  OF  THE  THEORY
 *  OF  LIABILITY,  ARISING  OUT  OF  THE  USE  OF  OR  INABILITY  TO  USE  THIS  SOFTWARE,
 *  EVEN  IF  IFAA  HAS  BEEN  ADVISED  OF  THE  POSSIBILITY  OF  SUCH  DAMAGES.
 *
 *  You  acknowledge  that  this  software  is  not  designed,  licensed  or  intended
 *  for  use  in  the  design,  construction,  operation  or  maintenance  of  any
 *  nuclear  facility.
 *
 */
package com.ifaa.sdk.authenticatorservice.message;

/**
 * 
 * @author junsui.ljs
 * @version 1.0
 */
public class Result {

    public static String    TAG                                         = Result.class.getSimpleName();


    public static final int IFAA_ERR_SUCCESS                     = 0x00000000;   //success
    public static final int IFAA_ERR_UNKNOWN                     = 0x7A000001;   //unknown error
    public static final int IFAA_ERR_BAD_ACCESS                  = 0x7A000002;   //access error
    public static final int IFAA_ERR_BAD_PARAM                   = 0x7A000003;   //wrong input
    public static final int IFAA_ERR_UNKNOWN_CMD                 = 0x7A000004;   //unknown cmd
    public static final int IFAA_ERR_BUF_TOO_SHORT               = 0x7A000005;   //too short buffer
    public static final int IFAA_ERR_OUT_OF_MEM                  = 0x7A000006;   //fail to allocate memory
    public static final int IFAA_ERR_TIMEOUT                     = 0x7A000007;   //time out
    public static final int IFAA_ERR_HASH                        = 0x7A000008;   //HASH fails
    public static final int IFAA_ERR_SIGN                        = 0x7A000009;   //fail to sign
    public static final int IFAA_ERR_VERIFY                      = 0x7A00000A;   //fail to verify
    public static final int IFAA_ERR_KEY_GEN                     = 0x7A00000B;   //fail to generate key
    public static final int IFAA_ERR_READ                        = 0x7A00000C;   //fail to read file
    public static final int IFAA_ERR_WRITE                       = 0x7A00000D;   //fail to write file
    public static final int IFAA_ERR_ERASE                       = 0x7A00000E;   //fail to match file
    public static final int IFAA_ERR_NOT_MATCH                   = 0x7A00000F;   //unmatched biometric infor
    public static final int IFAA_ERR_GEN_RESPONSE                = 0x7A000010;   //fail to generate response
    public static final int IFAA_ERR_GET_DEVICEID                = 0x7A000011;   //fail to get device ID
    public static final int IFAA_ERR_GET_LAST_IDENTIFIED_RESULT  = 0x7A000012;   //get the last failure of verification
    public static final int IFAA_ERR_AUTHENTICATOR_SIGN          = 0x7A000013;   //fail to sign Authenticator certificate
    public static final int IFAA_ERR_GET_ID_LIST                 = 0x7A000014;   //fail to get the id list
    public static final int IFAA_ERR_GET_AUTHENTICATOR_VERSION   = 0x7A000015;   //failt to get the version of Authenticator
    public static final int IFAA_ERR_UN_INITIALIZED              = 0x7A000016;   //initialization fail
    public static final int IFAA_ERR_NO_OPTIONAL_LEVEL           = 0x7A000017;   //no optioncal level
    /**
     * success and fail
     */
    public static final int RESULT_SUCCESS                              = 0;
    public static final int RESULT_FAIL                                 = 0xFFFF0000;

    /**
     * status
     */
    protected int           status                                      = -1;

    /**
     * data
     */
    protected byte[]        data;

    /**
     * Constructor
     */
    public Result() {
        super();
    }

    /**
     * Constructor
     * @param status
     * @param data
     */
    public Result(int status, byte[] data) {
        super();
        this.status = status;
        this.data = data;
    }

    /**
     * Getter method for property <tt>status</tt>.
     * 
     * @return property value of status
     */
    public int getStatus() {
        return status;
    }

    /**
     * Setter method for property <tt>status</tt>.
     * 
     * @param status value to be assigned to property status
     */
    public void setStatus(int status) {
        this.status = status;
    }

    /**
     * Getter method for property <tt>data</tt>.
     * 
     * @return property value of data
     */
    public byte[] getData() {
        return data;
    }

    /**
     * Setter method for property <tt>data</tt>.
     * 
     * @param data value to be assigned to property data
     */
    public void setData(byte[] data) {
        this.data = data;
    }

    // FIXMI : REMOVE by qiyi, when modify fingerprint service, repair it
    //    /**
    //     * convert from hw resultCode
    //     * 
    //     * @param resultCode
    //     * @return
    //     */
    //    public static int convertFP(int resultCode) {
    //
    //        if (resultCode == AbstractFingerprint.RESULT_SUCCESS) {
    //            return AuthenticatorResponse.RESULT_SUCCESS;
    //        } else if (resultCode == AbstractFingerprint.RESULT_CANCELED) {
    //            return AuthenticatorResponse.RESULT_CANCELED;
    //        } else if (resultCode == AbstractFingerprint.RESULT_TIMEOUT) {
    //            return AuthenticatorResponse.RESULT_TIMEOUT;
    //        } else if (resultCode == AbstractFingerprint.RESULT_NO_MATCH) {
    //            return AuthenticatorResponse.RESULT_NO_MATCH;
    //        } else if (resultCode == AbstractFingerprint.RESULT_NOT_REGISTERED_FINGERPRINT) {
    //            return AuthenticatorResponse.RESULT_NOT_ENROLLED;
    //        } else if (resultCode == AbstractFingerprint.RESULT_NOT_ENABLED) {
    //            return AuthenticatorResponse.RESULT_NOT_ENABLED;
    //        } else if (resultCode == AbstractFingerprint.RESULT_SENSOR_ERROR) {
    //            return AuthenticatorResponse.RESULT_SENSOR_ERROR;
    //        }
    //        return AuthenticatorResponse.RESULT_FAILURE;
    //    }


    public static String getStatusStringIFAA2(int status) {
        switch(status) {
            case IFAA_ERR_SUCCESS:
                return "IFAA_ERR_SUCCESS";
            case IFAA_ERR_UNKNOWN:
                return "IFAA_ERR_UNKNOWN";
            case IFAA_ERR_BAD_ACCESS:
                return "IFAA_ERR_BAD_ACCESS";
            case IFAA_ERR_BAD_PARAM:
                return "IFAA_ERR_BAD_PARAM";
            case IFAA_ERR_UNKNOWN_CMD:
                return "IFAA_ERR_UNKNOWN_CMD";
            case IFAA_ERR_BUF_TOO_SHORT:
                return "IFAA_ERR_BUF_TOO_SHORT";
            case IFAA_ERR_OUT_OF_MEM:
                return "IFAA_ERR_OUT_OF_MEM";
            case IFAA_ERR_TIMEOUT:
                return "IFAA_ERR_TIMEOUT";
            case IFAA_ERR_HASH:
                return "IFAA_ERR_HASH";
            case IFAA_ERR_SIGN:
                return "IFAA_ERR_SIGN";
            case IFAA_ERR_VERIFY:
                return "IFAA_ERR_VERIFY";
            case IFAA_ERR_KEY_GEN:
                return "IFAA_ERR_KEY_GEN";
            case IFAA_ERR_READ:
                return "IFAA_ERR_READ";
            case IFAA_ERR_WRITE:
                return "IFAA_ERR_WRITE";
            case IFAA_ERR_ERASE:
                return "IFAA_ERR_ERASE";
            case IFAA_ERR_NOT_MATCH:
                return "IFAA_ERR_NOT_MATCH";
            case IFAA_ERR_GEN_RESPONSE:
                return "IFAA_ERR_GEN_RESPONSE";
            case IFAA_ERR_GET_DEVICEID:
                return "IFAA_ERR_GET_DEVICEID";
            case IFAA_ERR_GET_LAST_IDENTIFIED_RESULT:
                return "IFAA_ERR_GET_LAST_IDENTIFIED_RESULT";
            case IFAA_ERR_AUTHENTICATOR_SIGN:
                return "IFAA_ERR_AUTHENTICATOR_SIGN";
            case IFAA_ERR_GET_ID_LIST:
                return "IFAA_ERR_GET_ID_LIST";
            case IFAA_ERR_GET_AUTHENTICATOR_VERSION:
                return "IFAA_ERR_GET_AUTHENTICATOR_VERSION ";
            case IFAA_ERR_UN_INITIALIZED:
                return "IFAA_ERR_UN_INITIALIZED";
            case IFAA_ERR_NO_OPTIONAL_LEVEL:
                return "IFAA_ERR_NO_OPTIONAL_LEVEL";
            default:
                return "NOT_SUPPORT_ERROR_TYPE["+ status + "]";
        }
    }

    public class StatusCode {
        /**
         * wait for input
         */
        public final static int STATUS_WAITING_FOR_INPUT = 1;

        /**
         * inputting
         */
        public final static int STATUS_INPUTTING         = 2;

        /**
         * input finish
         */
        public final static int STATUS_INPUT_COMPLETED   = 3;

        /**
         * return status
         */
        public static final int RESULT_SUCCESS           = 100; //user cancel
        public static final int RESULT_FAIL              = 101; //fail to verify fingerprint
        public static final int RESULT_CANCELED          = 102; //user cancel
        public static final int RESULT_NO_MATCH          = 103; //not match fingerprint
        public static final int RESULT_TIMEOUT           = 113; //time out
        /**
         * user status
         */
        public static final int USER_STATUS_NOT_REGISTER = 0;  //unregistered user
        public static final int USER_STATUS_IDX_REMOVE   = 1;  //already open. The index is already deleted.
        public static final int USER_STATUS_REGISTER     = 2;  //already open，status normal
    }
}
